use std::fmt;

// 基础能力
trait Courier: fmt::Display {
    fn deliver(&self, address: &str) -> String;
    fn vehicle(&self) -> String { String::from("基础运输车") }
}

// 显示能力
impl fmt::Display for StandardCourier {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "标准快递员#{}", self.id)
    }
}

// VIP能力继承
trait VIPCourier: Courier {
    fn special_delivery(&self) -> String;
}

// 条件实现重量检测
trait WeightCheck {
    fn max_weight(&self) -> u32;
}
impl<T: Courier> WeightCheck for T {
    fn max_weight(&self) -> u32 {
        match self.vehicle().as_str() {
            "自行车" => 50,
            "反重力飞行器" => 5000,
            _ => 200
        }
    }
}

fn main() {
    // 创建各类型快递员
    let team: Vec<Box<dyn Courier>> = vec![
        Box::new(StandardCourier { id: 2048 }),
        Box::new(RobotCourier { model: "RX-2023".into() })
    ];

    // 展示综合能力
    for member in team {
        println!("\n====== 快递员档案 ======");
        println!("{}", member);
        println!("交通工具：{}", member.vehicle());
        println!("载重上限：{}kg", member.max_weight());
        println!("任务日志：{}", member.deliver("仙女座星系"));
    }
}

trait Courier {
    fn deliver(&self, address: &str) -> String; // 必须实现的配送方法
    fn vehicle(&self) -> String { // 默认交通工具
        String::from("自行车")
    }
}
struct StandardCourier {
    id: u32
}

impl Courier for StandardCourier {
    fn deliver(&self, address: &str) -> String {
        format!("{}号快递员骑{}前往{}", self.id, self.vehicle(), address)
    }
}


struct RobotCourier {
    model: String
}

impl Courier for RobotCourier {
    fn deliver(&self, address: &str) -> String {
        format!("{}型号机器人飞往{}", self.model, address)
    }
    
    // 覆盖默认交通工具
    fn vehicle(&self) -> String {
        String::from("反重力飞行器")
    }
}


trait VIPCourier: Courier { // 继承基础能力
    fn special_package(&self) -> String; // 新增特殊包裹处理能力
}

struct SuperRobot {
    version: u32
}

impl Courier for SuperRobot {
    fn deliver(&self, address: &str) -> String {
        format!("{}代超级机器人直达{}", self.version, address)
    }
}

impl VIPCourier for SuperRobot {
    fn special_package(&self) -> String {
        String::from("正在运送反物质燃料")
    }
}


trait HeavyPackage {
    fn weight(&self) -> u32;
}

impl<T: Courier> HeavyPackage for T {
    fn weight(&self) ->
}

fn assemble_team() -> Vec<Box<dyn Courier>> {
    vec![
        Box::new(StandardCourier { id: 1024 }),
        Box::new(RobotCourier { model: "TX-1000".into() })
    ]
}

for member in assemble_team() {
    println!("{}", member.deliver("银河快递站")); 
}
/* 输出：
1024号快递员骑自行车前往银河快递站
TX-1000型号机器人飞往银河快递站
*/
trait Dangerous {
    fn boom(&self) -> Self; // 返回Self违反对象安全
}

// 无法创建trait对象
// let trouble: Box<dyn Dangerous> = ...; // 编译器将阻止
